﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MVCTutorial.Core.Impls.Repository;

namespace MVCTutorial.Core.Model
{
	public class Skill
	{
		public int Id { get; internal set; }
		public string Description { get; set; }

		public Skill(string description)
		{
			Description = description;
		}

		internal Skill(int id, string description)
		{
			Id = id;
			Description = description;
		}

		public void Save()
		{
			ISkillRepository skillRepo = RepositoryProvider.SkillRepository;

			if (Id == 0)
				skillRepo.Add(this);
			else
				skillRepo.Update(this);
		}

		public static void Delete(int id)
		{
			ISkillRepository skillRepo = RepositoryProvider.SkillRepository;
			skillRepo.Remove(id);
		}

		internal static IEnumerable<Skill> GetAll()
		{
			return RepositoryProvider.SkillRepository.GetAll();
		}
	}
}